﻿using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace Onshi.POS.Modelo.Objetos
{
    public class ManejoImagen
    {
        #region Metodos

        public static Byte[] ImagenAByte(Image imagen)
        {
            try
            {
                if (imagen == null)
                    return null;

                var ms = new MemoryStream();
                var bm = new Bitmap(imagen);
                bm.Save(ms, ImageFormat.Jpeg);
                return ms.ToArray();
            }
            catch (Exception)
            {
                return null;
            }
        }

        public static Image ByteAImagen(Byte[] imagen)
        {
            try
            {
                var ms = new MemoryStream(imagen);
                return Image.FromStream(ms);
            }
            catch (Exception)
            {
                return null;
            }
        }

        #endregion
    }
}
